import datetime
import logging as log
import uuid

from google.appengine.api import users

import base
import models

class Main(base.RequestHandler):

    def get(self, *args):
        self.post(*args)

    def post(self, *args):
        args = {
            "name": self.request.get("name", "New Bug"),
            "version": self.request.get("version"),
            "source": self.request.get("source"),
            "fixed": False,
            "submitted": datetime.datetime.now(),
            "submitter": users.get_current_user()
        }
        log.info(args)
        bug = models.Bug(**args)
        bug.put()
        dest = self.request.get("destination", None)
        if dest is not None:
            self.redirect(dest)
        else:
            self.json({"ok": True})